package tech.xs.sys.domain.bo.user;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tech.xs.common.framework.domain.bo.PageBo;
import tech.xs.common.framework.domain.entity.BaseEntity;
import tech.xs.common.sys.domain.enums.SysAccountStatusEnum;
import tech.xs.sys.domain.entity.SysUser;

/**
 * @author 沈家文
 * @since 2023/6/8 17:13
 */
@Getter
@Setter
@ToString
public class PageUserBo extends PageBo<SysUser> {

    private String likeUserName;

    private String likePhone;

    private String likeEmail;

    private String likeRealName;

    private String likeIdNumber;

    private SysAccountStatusEnum accountStatus;

    public LambdaQueryWrapper<SysUser> query() {
        return Wrappers.<SysUser>lambdaQuery()
                .eq(accountStatus != null, SysUser::getAccountStatus, accountStatus)
                .like(StrUtil.isNotBlank(likeIdNumber), SysUser::getIdNumber, likeIdNumber)
                .like(StrUtil.isNotBlank(likeRealName), SysUser::getRealName, likeRealName)
                .like(StrUtil.isNotBlank(likeEmail), SysUser::getEmail, likeEmail)
                .like(StrUtil.isNotBlank(likePhone), SysUser::getPhone, likePhone)
                .like(StrUtil.isNotBlank(likeUserName), SysUser::getUserName, likeUserName)
                .orderByDesc(BaseEntity::getCreatedTime);
    }

}
